<template>
	<view :style="colorStyle">
		<view class="top-tabs">
			<view class="tabs" :class="{btborder:type == index}" v-for="(item,index) in tabsList" :key="index"
				@tap="changeTabs(index)">
				{{item.name}}
			</view> 
		</view>
		<view class='return-list items' v-if="orderList.length">
			<view class='item' v-for="(item,index) in orderList" :key="index"
				@click='goOrderDetails(item.id,item.order_no)'>
				<view class="top">
					<view class="sn_no">{{item.o_sn}}</view>
					<view class="status" v-if="item.status == 0">待确认</view>
					<view class="status" v-if="item.status == 1">待接单</view>
					<view class="status" v-if="item.status == 2">司机待支付</view>
					<view class="status" v-if="item.status == 3">待装货</view>
					<view class="status" v-if="item.status == 4">待送达</view>
					<view class="status" v-if="item.status == 5">待支付</view>
					<view class="status" v-if="item.status == 6">待评价</view>
					<view class="status" v-if="item.status == 7">已完成</view>
					<view class="status" v-if="item.status == 8">已取消</view>
				</view>
				<view class="item_title">
					<view class="title">
					{{item.name}}【{{item.wrap_way}}】
					{{item.weight_start == item.weight_end?item.weight_start+"吨":item.weight_start+"-"+item.weight_end+"吨"}}
					{{item.volumn_start == item.volumn_end?item.volumn_start+"方":item.volumn_start+"-"+item.volumn_end+"方"}}
					</view>
					<view class="time">{{item.setup_time}}</view>
				</view><!--top end-->
				<view class="types">
					{{item.type == 0?'整车':'零担'}}  {{item.car_type_len}}
				</view><!--types end-->
				<view class="address_start">
					<view class="sta">装</view>
					<view class="address">{{item.start_province}}{{item.start_city}}{{item.start_distinct}}{{item.start_address}}</view>
				</view><!--address_start end-->
				<view class="address_end">
					<view class="end">卸</view>
					<view class="address">{{item.end_province}}{{item.end_city}}{{item.end_distinct}}{{item.end_address}}</view>
				</view><!--address_start end-->
			</view>
		</view>
		<view class='loadingicon acea-row row-center-wrapper' v-if="orderList.length > 0">
			<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
		</view>
		<view v-if="orderList.length == 0  && !loading">
			<emptyPage :title="$t(`暂无订单~`)"></emptyPage>
		</view>
		<!-- #ifdef MP -->
		<!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
		<!-- #endif -->
		<!-- #ifndef MP -->
		<home></home>
		<!-- #endif -->
	</view>
</template>

<script>
	import home from '@/components/home';
	import emptyPage from '@/components/emptyPage';
	import {logisticOrderList} from '@/api/logistic_order.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	// #ifdef MP
	import authorize from '@/components/Authorize';
	// #endif
	import colors from '@/mixins/color.js';
	export default {
		components: {
			home,
			emptyPage,
			// #ifdef MP
			authorize
			// #endif
		},
		mixins: [colors],
		data() {
			return {
				type: 0,
				loading: false,
				loadend: false,
				loadTitle: this.$t(`加载更多`), //提示语
				orderList: [], //订单数组
				orderStatus: -3, //订单状态
				page: 1,
				limit: 10,
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false, //是否隐藏授权
				tabsList: [{
					key: 0,
					name: this.$t(`全部`)
				},
				{
					key: 1,
					name: this.$t(`待确认`)
				},
				{
					key: 2,
					name: '运输中'
				}, 
				{
					key: 3,
					name: '待支付'
				}, 
				{
					key: 4,
					name: this.$t(`待评价`)
				}, 
				{
					key: 5,
					name: this.$t(`已取消`)
				}]
			};
		},
		computed: mapGetters(['isLogin']),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV) {
						this.getOrderList();
					}
				},
				deep: true
			}
		},
		onLoad(options) {
			console.info(options.type)
			if(options.type == undefined){
				this.type = 0;
			}else{
				this.type = options.type;
			}
			if (this.isLogin) {
				this.getOrderList();
			} else {
				toLogin();
			}
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			console.info('加载更多')
			this.getOrderList();
		},
		onPullDownRefresh() {
			this.page = 1;
			this.getOrderList();
		},
		methods: {
			onLoadFun() {
				this.getOrderList();
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
			/**
			 * 去订单详情
			 */
			goOrderDetails: function(order_id,order_no) {
				/*
				
				*/
				if (!order_id) return that.$util.Tips({
					title: that.$t(`缺少订单号无法查看订单详情`)
				});
				uni.navigateTo({
					url: '/pages/news/order/detail?id=' + order_id
				})
			},
			changeTabs(index) {
				console.info(index)
				this.type = index
				this.loadend = false;
				this.page = 1
				this.limit = 10
				this.orderList = []
				this.getOrderList(index)
			},
			/**
			 * 获取订单列表
			 */
			getOrderList(type) {
				let that = this;
				if (that.loading) return;
				if (that.loadend) return;
				uni.showLoading({
					title:'加载中...'
				});
				that.loading = true;
				that.loadTitle = "";
				logisticOrderList({
					// type: that.orderStatus,
					page: that.page,
					limit: that.limit,
					type: type ? type : that.type
				}).then(res => {
					uni.hideLoading();
					console.info(res)
					let list = res.data.list || [];
					let loadend = list.length < that.limit;
					that.orderList = that.orderList.concat(list);
					that.$set(that, 'orderList', that.orderList);
					that.loadend = loadend;
					that.loading = false;
					that.loadTitle = loadend ? that.$t(`我也是有底线的`) : that.$t(`加载更多`);
					that.page = that.page + 1;
				}).catch(err => {
					uni.hideLoading();
					that.loading = false;
					that.loadTitle = that.$t(`加载更多`);
				});
			}
		},
		 //时间戳的处理    
		filters: {
			formatDate: function(value) {
				var date = new Date(value);
				//date.setTime(value);
				var month = date.getMonth() + 1;
				if(month < 10){
					month = "0" + month;
				}
				var hours = date.getHours();
				if (hours < 10)
					hours = "0" + hours;
				var minutes = date.getMinutes();
				if (minutes < 10)
					minutes = "0" + minutes;
				var time = month + "-" + date.getDate() +
					" " + hours + ":" + minutes;
				return time;
			}
 
		},
	}
</script>

<style lang="scss" scoped>
	.items{
		display: flex;
		flex-direction: column;
		.item{
			background-color: white;
			display: flex;
			flex-direction: column;
			padding: 30rpx;
			border-radius: 10rpx;
			margin-top: 13rpx;
			.top{
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				height: 50rpx;
				border-bottom: 1rpx solid #f1f1f1;
				.sn_no{
					font-size: 28rpx;
					color: darkgray;
				}
				.status{
					font-size: 28rpx;
					color: indianred;
				}
			}
			.item_title{
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				margin-top: 20rpx;
				.title{
					color: black;
					font-size: 28rpx;
					font-weight: bold;
				}
				.time{
					color: black;
					font-size: 28rpx;
				}
			}
			.types{
				display: flex;
				flex-direction: row;
				font-size: 28rpx;
				color: black;
				margin-top: 10rpx;
			}
			.address_start{
				display: flex;
				flex-direction: row;
				// align-items: center;
				// height: 40rpx;
				margin-top: 10rpx;
				.sta{
					width: 40rpx;
					height:36rpx;
					background-color: #008CFF;
					color: white;
					font-size: 20rpx;
					text-align: center;
					line-height: 36rpx;
					border-radius: 6rpx;
				}
				.address{
					color: black;
					font-size: 28rpx;
					margin-left: 15rpx;
				}
			}
			.address_end{
				margin-top: 15rpx;
				display: flex;
				// flex-direction: row;
				align-items: center;
				// height: 40rpx;
				.end{
					width: 40rpx;
					height:36rpx;
					background-color: #FF8F00;
					color: white;
					font-size: 20rpx;
					text-align: center;
					line-height: 36rpx;
					border-radius: 6rpx;
				}
				.address{
					color: black;
					font-size: 28rpx;
					margin-left: 15rpx;
				}
			}
		}
	}
	
	.top-tabs {
		display: flex;
		justify-content: space-around;
		align-items: center;
		height: 80rpx;
		background-color: #fff;
	}

	.top-tabs .tabs {
		position: relative;
		height: 100%;
		padding: 12px 0;
	}

	.btborder {
		&::after {
			position: absolute;
			content: ' ';
			width: 39px;
			height: 2px;
			background-color: var(--view-theme);
			bottom: 2px;
			left: 50%;
			margin-left: -19px;
		}
	}
</style>
